package site.lanmushan.quiz.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import site.lanmushan.common.bizlog.annotations.BizLog;
import site.lanmushan.common.bizlog.consts.BizLogType;
import site.lanmushan.common.dto.Message;
import site.lanmushan.common.dto.QueryInfo;
import site.lanmushan.common.query.annotations.RequestQueryInfo;
import site.lanmushan.common.query.controller.BaseController;
import site.lanmushan.quiz.api.ao.QuizTbBankReportAo;
import site.lanmushan.quiz.api.entity.QuizTbBankReport;
import site.lanmushan.quiz.api.service.IQuizTbBankReportService;

import javax.validation.Valid;
import java.util.List;

/**
 * @author $author
 * 测验报告
 */
@RestController
@RequestMapping(name = "测验报告", value = "/QuizTbBankReport")
@Slf4j
public class QuizTbBankReportController extends BaseController {
    @Autowired
    IQuizTbBankReportService IQuizTbBankReportService;

    @BizLog(name = "测验报告-分页条件查询", bizType = BizLogType.SELECT)
    @GetMapping(name = "分页条件查询", value = "/selectPageList")
    public Message<List<QuizTbBankReport>> selectPageList(@RequestQueryInfo QueryInfo queryInfo) {
        List<QuizTbBankReport> quizTbBankReportList = IQuizTbBankReportService.selectPageList(queryInfo);
        return Message.getInstance().setData(quizTbBankReportList).success("查询成功");
    }

    @BizLog(name = "测验报告-根据ID查询", bizType = BizLogType.SELECT)
    @GetMapping(name = "根据ID查询", value = "/selectById")
    public Message<QuizTbBankReport> selectById(@RequestParam Long id) {
        QuizTbBankReport resultEntity = IQuizTbBankReportService.selectById(id);
        return Message.getInstance().setData(resultEntity).success("查询成功");
    }

    @BizLog(name = "测验报告-新增", bizType = BizLogType.INSERT)
    @PostMapping(name = "新增", value = "/save")
    public Message<Long> saveEntity(@RequestBody @Valid QuizTbBankReportAo entityAo) {
        IQuizTbBankReportService.insertService(entityAo);
        return Message.getInstance().setData(entityAo.getId()).success();
    }

    @BizLog(name = "测验报告-批量新增", bizType = BizLogType.INSERT)
    @PostMapping(name = "批量新增", value = "/saveList")
    public Message<List<Long>> saveEntityList(@RequestBody @Valid List<QuizTbBankReportAo> entityAos) {
        List<Long> ids = IQuizTbBankReportService.insertList(entityAos);
        return Message.getInstance().setData(ids).success();
    }

    @BizLog(name = "测验报告-更新", bizType = BizLogType.UPDATE)
    @PostMapping(name = "更新", value = "/update")
    public Message<Boolean> updateEntity(@RequestBody @Valid QuizTbBankReportAo entityAo) {
        IQuizTbBankReportService.updateService(entityAo);
        return Message.getInstance().success();
    }

    @BizLog(name = "测验报告-批量更新", bizType = BizLogType.UPDATE)
    @PostMapping(name = "批量更新", value = "/updateList")
    public Message<Integer> updateEntityList(@RequestBody @Valid List<QuizTbBankReportAo> entityAos) {
        Integer count = IQuizTbBankReportService.updateListBySelective(entityAos);
        return Message.getInstance().setData(count).success();
    }

    @BizLog(name = "测验报告-逻辑删除", bizType = BizLogType.DELETE)
    @PostMapping(name = "逻辑删除", value = "/logicDelete")
    public Message<Boolean> logicDelete(@RequestBody List<Long> ids) {
        IQuizTbBankReportService.logicDeleteByIds(ids);
        return Message.getInstance().success();
    }

    @BizLog(name = "测验报告-物理删除", bizType = BizLogType.DELETE)
    @PostMapping(name = "物理删除", value = "/delete")
    public Message<Boolean> delete(@RequestBody List<Long> ids) {
        IQuizTbBankReportService.deleteServiceByIds(ids);
        return Message.getInstance().success();
    }


}
